package testing.funzionale.sistema;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import jsudoku.Sudoku;
import jsudoku.SudokuFileManager;
import jsudoku.exception.InvalidSudokuException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestingApriPartita {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	//File corretto
	@Test
	public void testOpenSudoku1() {
		File f = new File("Impossibile.sdk");
		SudokuFileManager s = new SudokuFileManager(f);
		try {
			Sudoku sudoku = s.openSudoku();
			int[][] matrice = {
					
					{0, 8, 4, 5, 7, 2, 9, 1, 3},
					{9, 3, 2, 8, 6, 1, 7, 5, 4},
					{5, 1, 7, 9, 4, 3, 6, 8, 2},
					{3, 4, 9, 2, 5, 8, 1, 6, 7},
					{1, 6, 8, 3, 9, 7, 4, 2, 5},
					{7, 2, 5, 6, 1, 4, 8, 0, 9},
					{4, 7, 3, 0, 2, 6, 5, 9, 8},
					{2, 5, 1, 4, 8, 9, 3, 7, 6},
					{0, 9, 6, 7, 3, 5, 2, 4, 1}
					
			};
			
			boolean x = true;
			
			for (int i=0; i<9; i++){
				for (int j=0; j<9; j++){
					if (sudoku.getSudoku()[i][j]!=matrice[i][j]){
						x=false;
					}
				}
			}
			
			assertTrue(x);
			
		} catch (FileNotFoundException e) {
			
		} catch (IOException e) {
			
		} catch (InvalidSudokuException e) {
			
		}
		
	}
	
	//File corretto
	@Test
	public void testOpenSudoku2() {
		File f = new File("Impossibile");
		SudokuFileManager s = new SudokuFileManager(f);
		try {
			Sudoku sudoku = s.openSudoku();
			int[][] matrice = {
					
					{0, 8, 4, 5, 7, 2, 9, 1, 3},
					{9, 3, 2, 8, 6, 1, 7, 5, 4},
					{5, 1, 7, 9, 4, 3, 6, 8, 2},
					{3, 4, 9, 2, 5, 8, 1, 6, 7},
					{1, 6, 8, 3, 9, 7, 4, 2, 5},
					{7, 2, 5, 6, 1, 4, 8, 0, 9},
					{4, 7, 3, 0, 2, 6, 5, 9, 8},
					{2, 5, 1, 4, 8, 9, 3, 7, 6},
					{0, 9, 6, 7, 3, 5, 2, 4, 1}
					
			};
			
			boolean x = true;
			
			for (int i=0; i<9; i++){
				for (int j=0; j<9; j++){
					if (sudoku.getSudoku()[i][j]!=matrice[i][j]){
						x=false;
					}
				}
			}
			
			assertTrue(x);
			
		} catch (FileNotFoundException e) {
			
		} catch (IOException e) {
			
		} catch (InvalidSudokuException e) {
			
		}
		
	}
	/*
	//File non esistente
	@Test
	public void testOpenSudoku3() {
		File f = new File("nonEsisto");
		SudokuFileManager s = new SudokuFileManager(f);
		boolean x = true;
		try {
			Sudoku sudoku = s.openSudoku();
			
			
		} catch (FileNotFoundException e) {
			x = false;
		} catch (IOException e) {
			x = false;
		} catch (InvalidSudokuException e) {
			x = false;
		} finally{
			assertFalse(x);
		}
		
	}
	
	//File con estensione diversa da sdk
	@Test
	public void testOpenSudoku4() {
		File f = new File("Impossibile.txt");
		SudokuFileManager s = new SudokuFileManager(f);
		boolean x = true;
		try {
			Sudoku sudoku = s.openSudoku();
			
		} catch (FileNotFoundException e) {
			x = false;
		} catch (IOException e) {
			x = false;
		} catch (InvalidSudokuException e) {
			x = false;
		} finally{
			assertFalse(x);
		}
		
	}
	*/
	//Matrice contente qualche carattere
	@Test
	public void testOpenSudoku5() {
		File f = new File("carattere");
		SudokuFileManager s = new SudokuFileManager(f);
		boolean x = true;
		try {
			Sudoku sudoku = s.openSudoku();
			
		} catch (FileNotFoundException e) {
			x = false;
		} catch (IOException e) {
			x = false;
		} catch (InvalidSudokuException e) {
			x = false;
		} finally{
			assertFalse(x);
		}
			
	}
	

}
